#include <cassert>
#include <cstdio>
#include <iostream>
#include "string.h"

using std::cout;
using std::endl;
using std::cerr;

void testConstruterAndDesconstruter(){
	String s1;
	char name[] = "Invoker Zhang";
	String s2(name);
	String s3('a', 5);
	String s4('b', 200);
	String s5(s2);

	String *str = new String("Hello world");
	delete str;
}

void testOperators(){
	String s1("hello ");
	String s2("world");
	String s3 = s1 + s2;
	assert(s1[1] == 'e');
	s3[0] = 'H';
	assert(s3[0] == 'H');
	s1 += s2 += '!';
	cout << "s1 should be 'hello world!':"
		<< s1 << endl;
}

int main(){
	testConstruterAndDesconstruter();
	testOperators();

	String s1("hello world!");
	cout << "s1 is: " << s1 << endl;
	assert(s1.size() == strlen("hello world!"));
	s1 = s1 + "??";
	cout << "After adding, s1 is: " << s1 << endl;

	char olds[100];
	strcpy(olds, s1.toStr());
	printf("printf string: %s\n", olds);
}
